<?php

define ("CW2_DEBUG", 1);

define ("CW2_PLANET_FORT", 0x01);
define ("CW2_PLANET_ONGOING_COMBAT", 0x02);
define ("CW2_UNIT_GARRISON", 0x01);

define ("CW2_MAX_STARLANES", 7);
define ("CW2_NO_OBJECT", -999);
define ("CW2_NO_SID", -998);

define ("CW2_CLAN_MEMBER", 0x01);
define ("CW2_CLAN_PLAYER", 0x02);
define ("CW2_CLAN_OWN_UNIT_ORDERS", 0x10);
define ("CW2_CLAN_EVERYONE_UNIT_ORDERS", 0x20);
define ("CW2_CLAN_BUILD_RECRUIT", 0x40);
define ("CW2_CLAN_ADMIN", 0x10000);
define ("CW2_MAX_CLAN_PERMISSIONS",  0x1FFFF);
define ("CW2_TOURNAMENT_MODERATOR",  0x80000);
define ("CW2_MAX_HUMAN_PERMISSIONS", 0xFFFFF);
define ("CW2_AUTO",                 0x100000);

define ("CW2_NO_ORDER", 0);
define ("CW2_ORDER_ORDER", 0x0400);
define ("CW2_ORDER_UNIT", 0x0800);
define ("CW2_ORDER_FORT", 0x1000);
define ("CW2_ORDER_ARMY", 0x2000);
define ("CW2_ORDER_GARRISON", 0x4000);
define ("CW2_ORDER_PLANET", 0x8000);

define ("CW2_ORDER_MAIN", 0x7FF);
define ("CW2_ORDER_CREATE", 0x01);
define ("CW2_ORDER_RECRUIT", 0x02);
define ("CW2_ORDER_MOVE", 0x03);
define ("CW2_ORDER_DESTROY", 0x04);
define ("CW2_ORDER_CHANGE_LOCATION", 0x05);
define ("CW2_ORDER_CHANGE_OWNERSHIP", 0x06);

define ("CW2_FORT_COST", 2000);
define ("CW2_MIN_UNIT_COST", 50);
define ("CW2_GLICKO_UNIT_COST", 700);
define ("CW2_COUNT_UNIT_COST", 200);

define ("CW2_ACCEPTED", 0x01);
define ("CW2_SQL_ERROR", 0x02);
define ("CW2_REJECTED_UNKNOWN", 0x04);
define ("CW2_REJECTED_CANT_CANCEL_PREVIOUS_ORDER", 0x08);
define ("CW2_REJECTED_CANT_CHANGE_PREVIOUS_ORDER", 0x10);
define ("CW2_REJECTED_TPLAYER_NOT_FOUND", 0x20);
define ("CW2_REJECTED_WRONG_TPLAYER_CLAN", 0x40);
define ("CW2_REJECTED_TPLAYER_PERMISSIONS", 0x80);
define ("CW2_REJECTED_COMMANDER_PERMISSIONS", 0x100);
define ("CW2_REJECTED_WRONG_COMMANDER_CLAN", 0x200);
define ("CW2_REJECTED_NO_PLANET", 0x400);
define ("CW2_REJECTED_NO_UNIT", 0x800);
define ("CW2_REJECTED_WRONG_PLANET_TOURNAMENT", 0x1000);
define ("CW2_REJECTED_WRONG_ORDER_TOURNAMENT", 0x2000);
define ("CW2_REJECTED_WRONG_ORDER_TURN", 0x04000);
define ("CW2_REJECTED_WRONG_ALIGN_CLAN", 0x08000);

// order_permissions - min permissions to give order, align - order is being aligned to that object(recruit on a planet, move a unit etc.), tplayer_permissions - non-zero means that order has tplayer that does action (recruits unit etc.) and defines min permissions for a valid tplayer for that order

$order_types = array(
 (CW2_ORDER_CREATE+CW2_ORDER_UNIT+CW2_ORDER_ARMY) => array ('order_permissions' => CW2_TOURNAMENT_MODERATOR, 'align' => CW2_ORDER_PLANET, 'tplayer_permissions' => CW2_CLAN_PLAYER, 'view_permissions' => CW2_CLAN_MEMBER),

 (CW2_ORDER_CREATE+CW2_ORDER_UNIT+CW2_ORDER_GARRISON) =>  array ('order_permissions' => CW2_TOURNAMENT_MODERATOR, 'align' => CW2_ORDER_PLANET, 'tplayer_permissions' => CW2_CLAN_PLAYER, 'view_permissions' => CW2_CLAN_MEMBER),

 (CW2_ORDER_CREATE+CW2_ORDER_FORT) =>  array ('order_permissions' => CW2_TOURNAMENT_MODERATOR, 'align' => CW2_ORDER_PLANET, 'non_neutral' => true, 'view_permissions' => CW2_CLAN_MEMBER),

 (CW2_ORDER_RECRUIT+CW2_ORDER_UNIT+CW2_ORDER_ARMY) => array ('order_permissions' => CW2_CLAN_BUILD_RECRUIT, 'align' => CW2_ORDER_PLANET, 'tplayer_permissions' => CW2_CLAN_PLAYER, 'view_permissions' => CW2_CLAN_MEMBER),

 (CW2_ORDER_RECRUIT+CW2_ORDER_UNIT+CW2_ORDER_GARRISON) => array ('order_permissions' => CW2_CLAN_BUILD_RECRUIT, 'align' => CW2_ORDER_PLANET, 'tplayer_permissions' => CW2_CLAN_PLAYER, 'view_permissions' => CW2_CLAN_MEMBER),

 (CW2_ORDER_RECRUIT+CW2_ORDER_FORT) => array ('order_permissions' => CW2_CLAN_BUILD_RECRUIT, 'align' => CW2_ORDER_PLANET, 'view_permissions' => CW2_CLAN_MEMBER),

 CW2_ORDER_MOVE => array ('order_permissions' => CW2_CLAN_OWN_UNIT_ORDERS, 'destination' => true, 'align' => (CW2_ORDER_UNIT+CW2_ORDER_ARMY+CW2_ORDER_GARRISON), 'view_permissions' => CW2_CLAN_MEMBER),

 CW2_ORDER_DESTROY => array ('order_permissions' => CW2_TOURNAMENT_MODERATOR, 'align' => (CW2_ORDER_UNIT+CW2_ORDER_ARMY+CW2_ORDER_GARRISON+CW2_ORDER_FORT), 'view_permissions' => CW2_CLAN_MEMBER),

 CW2_ORDER_CHANGE_LOCATION => array ('order_permissions' => CW2_TOURNAMENT_MODERATOR, 'destination' => true, 'align' => (CW2_ORDER_UNIT+CW2_ORDER_ARMY+CW2_ORDER_GARRISON), 'view_permissions' => CW2_CLAN_MEMBER),
 
 (CW2_ORDER_CHANGE_OWNERSHIP+CW2_ORDER_PLANET) => array ('order_permissions' => CW2_TOURNAMENT_MODERATOR, 'align' => CW2_ORDER_PLANET, 'tgroup' => true, 'view_permissions' => CW2_CLAN_MEMBER)
 
);

$cw2 = 1;
require_once "../language.php";

function DBConn($i_mode = 0)
{
 if (__FILE__ == "C:\\Program Files\\Apache Software Foundation\\Apache2.2\\htdocs\\cw2\\CW2\\cw2conf.php")
 {
  // Ellestar - home
  $dbl=mysql_connect("localhost","isdga_cw2","test123");
  $cw2_db = "isdga_cw2";
 }
 else if (__FILE__ == "D:\\Program Files\\Apache Software Foundation\\Apache2.2\\htdocs\\CW2\\CW2\\cw2conf.php")
 {
  // Ellestar - work
  $dbl=mysql_connect("localhost","root","test123");
  $cw2_db = "cw";
 }
 else
 {
  // test site
  $dbl=mysql_connect("db5.awardspace.com","isdga_cw2","test123");
  $cw2_db = "isdga_cw2";
 }
 if (!$dbl) {die("Can't connect to MySQL database");};
 if ($i_mode == 0)
 {
  if (!mysql_select_db($cw2_db,$dbl))
  {
   die("Can't open database");
  };
 };
 return $dbl;
}

?>